﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.Entity;
using Legazpi.Payroll.DataAccess.Context;

namespace Legazpi.Payroll.DataAccess.Base
{
    public class DatabaseFactory : Disposable, IDatabaseFactory
    {
        private PayrollDataContext _dataContext;

        public PayrollDataContext Get()
        {
#if DEBUG
            var connStr = ConfigurationManager.ConnectionStrings[Environment.MachineName].ConnectionString;
#else
            var connStr = ConfigurationManager.ConnectionStrings["PayrollData"].ConnectionString;
#endif
            return _dataContext ?? (_dataContext = new PayrollDataContext(connStr));
        }
        protected override void DisposeCore()
        {
            if (_dataContext != null)
                _dataContext.Dispose();
        }
    }
}
